package com.example.springbootzklock.service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description: 生成订单号
 * @Author: mingtian
 * @CreateDate: 2019/9/24 20:29
 * @Version: 1.0
 */
public class OrderNumberGenerator {
    /**
     * zk 分布式锁 使用 static 共享
     */
    private static int count = 0;

    /**
     * 生成订单号
     *
     * @return
     */
    public String getNumber() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Thread.sleep(100);
        } catch (Exception e) {

        }
        return sdf.format(new Date()) + "-" + ++count;
    }
}
